package com.xrj.gateway.controller;

import com.mall.common.response.Response;
import com.mall.shopping.constant.ShoppingServiceEnum;
import com.mall.shopping.dto.bo.resp.ProductDetailResp;
import com.mall.shopping.service.TbItemService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: xrj
 * @date: 2022/5/3 20:19
 * @description:
 */
@RestController
@RequestMapping("/shopping")
public class ProductController {

    @Reference(timeout = 3000,check = false)
    private TbItemService itemService;

    @GetMapping("/product/{productId}")
    public Object getProductDetail(@PathVariable Long productId){
        if (productId == null) return Response.checkFailed("参数非法");
        ProductDetailResp resp = itemService.queryProductDetail(productId);
        if (!ShoppingServiceEnum.SUCCESS.getCode().equals(resp.getCode())){
            return Response.operationFailed(resp.getMsg());
        }
        return Response.success(resp.getDetailModel(),"查询成功");
    }

    @GetMapping("/comment/count")
    public Object getCommentCount(Long productId){
        return Response.success("评论功能暂未上线!");
    }
}
